using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace MusicEvolution.Database
{
	public class DataBaseRow
	{
        DataFieldList _fields;
		DataField _ID;

        public DataFieldList Fields
        {
            get { return _fields; }
        }
       
        public DataField this[string ColumnName]
        {
            get { return _fields[ColumnName]; }
            set { _fields[ColumnName] = value; }
        }

        public void Add(DataField field)
        {
            _fields.Add(field);
        }
		
		internal long ID
		{
			get
			{
                return Convert.ToInt64(_ID.Value);
			}
			set
			{
                _ID.Value = value.ToString();
			}
		}

        public DataBaseRow()
        {
            _fields = new DataFieldList();
            _ID = new DataField("ID", "");
            _fields.Add(_ID);
        }

        internal void Load(List<DataField> Values)
        {
            foreach (DataField field in Values)
            {
                try
                {
                    _fields[field.Name].Value = field.Value;
                }
                catch (Exception ex)
                {
                    Logging.Logger.LogMessage(Logging.MessageType.Debug, "DataBaseRow.Load", ex.ToString());
                }
            }

        }

        internal void Load(DataFieldList Values)
        {
            if (_fields == null) return;
            foreach (DataField field in Values)
            {
                try
                {
                    _fields[field.Name].Value = field.Value;
                }
                catch (Exception ex)
                {
                    Logging.Logger.LogMessage(Logging.MessageType.Debug, "DataBaseRow.Load", ex.ToString());
                }
            }
        }
	}
}
